﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Forms;
using YArchitech.BIM;
using YArchitech.Controls;
using YArchitech.LIB;
using YArchitech.LIB.YJKControls;

namespace YArchitech.HYSpace
{
	public partial class FrmAddTimeName : System.Windows.Forms.Form
	{
		public FrmAddTimeName()
		{
			this.InitializeComponent();
			base.Icon = Resource.YArchitechIcon;
		}

		public FrmAddTimeName(string tName)
		{
			this.InitializeComponent();
			base.Icon = Resource.YArchitechIcon;
			foreach (TimeAssign timeAssign in FrmTimeAssignManage.listTimeAssign)
			{
				if (timeAssign.Id.ToString() == tName)
				{
					this.typeName = timeAssign.TsParent;
					this.tAssign = FrmTimeAssignManage.SetTimeAssign(timeAssign);
					this.tAssign.Operation = "添加";
				}
			}
		}

		private void btnCancle_Click(object sender, EventArgs e)
		{
			base.Close();
		}

		private void FrmAddTimeName_Load(object sender, EventArgs e)
		{
			this.BindTypeName();
			this.cmbTimeType.SelectedItem = this.typeName;
		}

		private void BindTypeName()
		{
			this.cmbTimeType.Items.Add("人员");
			this.cmbTimeType.Items.Add("新风");
			this.cmbTimeType.Items.Add("照明");
			this.cmbTimeType.Items.Add("电子设备");
			this.cmbTimeType.Items.Add("电热设备");
			this.cmbTimeType.Items.Add("电动设备");
		}

		private void btnSure_Click(object sender, EventArgs e)
		{
			if (string.IsNullOrEmpty(this.txtTimeName.Text))
			{
				this.txtTimeName.Focus();
				return;
			}
			string text = this.cmbTimeType.SelectedItem + "_" + this.txtTimeName.Text.Trim();
			bool flag = false;
			IEnumerator<TimeAssign> enumerator = FrmTimeAssignManage.listTimeAssign.GetEnumerator();
			{
				while (enumerator.MoveNext())
				{
					if (enumerator.Current.TsName == text)
					{
						YJKMessageBox.Show("时间表不能重名");
						flag = true;
						break;
					}
				}
			}
			if (flag)
			{
				this.txtTimeName.SelectAll();
				this.txtTimeName.Focus();
				return;
			}
			int num = new LoadParamOperate().GetMaxTimeID();
			foreach (TimeAssign timeAssign in FrmTimeAssignManage.listTimeAssign)
			{
				if (timeAssign.Id > num)
				{
					num = timeAssign.Id;
				}
			}
			this.tAssign.Id = num + 1;
			this.tAssign.TsName = text;
			this.tAssign.TsParent = this.cmbTimeType.SelectedItem.ToString();
			base.DialogResult = DialogResult.Yes;
		}

		private string typeName = "";

		public TimeAssign tAssign = new TimeAssign();
	}
}
